package com.dyz.swordFingerOffer;

public class TreeDepth55 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(10);
        TreeNode node1 = new TreeNode(6);
        TreeNode node2 = new TreeNode(8);
        TreeNode node3 = new TreeNode(4);
        TreeNode node4 = new TreeNode(12);
        TreeNode node5 = new TreeNode(14);
        TreeNode node6 = new TreeNode(16);
        node1.left = node3;
        node1.right = node2;
        node5.left = node4;
        node5.right = node6;
        root.left = node1;
        root.right = node5;

        int a = new TreeDepth55().TreeDepth(root);
        System.out.println(a);

    }
    public int TreeDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        // 计算左子树的深度
        int left = TreeDepth(root.left);
        // 计算右子树的深度
        int right = TreeDepth(root.right);

        return left >= right ? (left + 1) : (right + 1);
    }
}
